﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;


namespace Zero.Data.Infrastructure
{
    public interface IRepository<T> where T : BaseEntity
    {
        
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        T Get(object id);
        
        
        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();

        /// <summary>
        /// 获取满足条件的实体集合
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> GetMany(Expression<Func<T, bool>> where);

        /// <summary>
        /// 根据键值获取指定实体
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        T Find(params object[] keys);

        /// <summary>
        /// 根据表达式条件获取实体
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        T Find(Expression<Func<T, bool>> where);

        /// <summary>
        /// 分页获取指定条件的集合
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="total"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        IQueryable<T> GetByPage(Expression<Func<T, bool>> filter, out int total, int page, int size);

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity"></param>
        void Add(T entity);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity"></param>
        void Update(T entity);

        /// <summary>
        /// 物理删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Remove(T entity);

        /// <summary>
        /// 根据物理删除实体
        /// </summary>
        /// <param name="id">主键</param>
        void Remove(object id);
        
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// 根据主键删除实体
        /// </summary>
        /// <param name="id">主键</param>
        void Delete(object id);

        /// <summary>
        /// 通过表达式删除实体
        /// </summary>
        /// <param name="where"></param>
        void Delete(Expression<Func<T, bool>> where);

        /// <summary>
        /// 获取实体数
        /// </summary>
        int Count { get; }
    }
}
